package org.example.chap01;

/**
 * https://leetcode-cn.com/problems/two-sum/
 *
 */
public class TwoSum {

    public static void main(String[] args) {

        int[] nums={2,7,11,15};
        int[] result=solution1(nums,9);
        for (int i = 0; i < result.length; i++) {
            System.out.println(result[i]);
        }

    }

    /**
     * 时间复杂度O(n^2)
     * @param nums
     * @param target
     * @return
     */
    public static int[] solution1(int[] nums, int target){
        int[] a = new int[2];
        int numSize = nums.length;
        for (int i = 0; i <numSize-1 ; i++) {
            for (int j = i+1; j < numSize; j++) {
                if(nums[i]+nums[j]==target){
                    a[0]=i;
                    a[1]=j;
                    return a;
                }
            }
        }
        return null;
    }

}
